//
//  ActivityCell.m
//  iHeima
//
//  Created by he chao on 6/16/14.
//  Copyright (c) 2014 leon. All rights reserved.
//

#import "ActivityCell.h"

@implementation ActivityCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)initSelf{
    imgCover = [BeeUIImageView spawn];
    imgCover.contentMode = UIViewContentModeScaleAspectFill;
    imgCover.frame = CGRectMake(5, 5, 120, 70);
    [self addSubview:imgCover];
    
    labelTitle = [BaseLabel initLabel:@"" font:FONT(14) color:RGB(84, 84, 84) textAlignment:NSTextAlignmentLeft];
    labelTitle.numberOfLines = 2;
    labelTitle.frame = CGRectMake(imgCover.right+5, imgCover.top, 160, 30);
    [self addSubview:labelTitle];
    
    for (int i = 0; i < 2; i++) {
        BeeUIImageView *imgIcon = [BeeUIImageView spawn];
        imgIcon.image = i==0?IMAGESTRING(@"time"):IMAGESTRING(@"location");
        imgIcon.frame = CGRectMake(labelTitle.left, labelTitle.bottom+22*i, 20, 20);
        [self addSubview:imgIcon];
        
        label[i] = [BaseLabel initLabel:@"" font:FONT(12) color:RGB(167, 167, 167) textAlignment:NSTextAlignmentLeft];
        label[i].frame = CGRectMake(imgIcon.right, imgIcon.top, 150, imgIcon.height);
        [self addSubview:label[i]];
    }
    
    imgStatus = [BeeUIImageView spawn];
    imgStatus.frame = CGRectMake(272, 40, 36, 17);
    [self addSubview:imgStatus];
    
}

- (void)load{
    [imgCover setImageWithURL:[NSString stringWithFormat:@"%@/%@",kBaseUrl,self.dictActivity[@"image"][0]] placeholderImage:nil];
    labelTitle.text = self.dictActivity[@"title"];
    label[0].text = [self getTime];
    label[1].text = self.dictActivity[@"address"];
    switch ([self.dictActivity[@"timeline"] intValue]) {
        case 1:
        {
            imgStatus.image = IMAGESTRING(@"status0");
        }
            break;
        case 2:
        {
            imgStatus.image = IMAGESTRING(@"status2");
        }
            break;
        case 3:
        {
            imgStatus.image = IMAGESTRING(@"status1");
        }
            break;
            
        default:
            break;
    }
}

- (NSString *)getTime{
    NSString *strTime = self.dictActivity[@"start_at"];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat : @"yyyy年M月d日 h:mm"];
    
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[strTime floatValue]];
    
    
    return [formatter stringFromDate:date];
}

@end
